package client.link.util;


public class ByteConvert {
    public static byte[] getByteFormInt(int value) {
        byte[] buffer = new byte[4];
        for (int i = 0; i < 4; i++) {
            buffer[i] = (byte) (value >> (8 * i));
        }
        return buffer;
    }
    
    public static int byte2Int(byte[] buffer) {
        if (buffer.length < 4) {
            throw new RuntimeException("the except size 4, but actually is "+buffer.length);
        }
        int int32 = 0;
        int32 = buffer[0] & 0xff;
        int32 |= ((int) buffer[1] << 8) & 0xff00;
        int32 |= ((int) buffer[2] << 16) & 0xff0000;
        int32 |= ((int) buffer[3] << 24) & 0xff000000;
        return int32;
    }
}
